#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int test1()
{
    // printf("%d",getpid());
    // chdir("/home/Jaxsen");
    FILE* fp = fopen("log.txt","w");
    if(fp == NULL)
    {
        perror("fopen");
        return 1;
    }
    const char* message = "hello\n";
    char message2[10];
    fscanf(fp,"%s",message2);
    printf("%s",message2);
    fclose(fp);
    // sleep(100);
    return 0;
}

int main()
{
    //fd是文件描述符
    umask(0);//让权限掩码在该进程中为0
    int fd = open("log.txt",O_RDWR|O_CREAT,0666);
    char buffer[1024] = "hello";
    write(fd,buffer,sizeof(buffer));
    
    char str[1024];
    ssize_t len = read(fd,str,sizeof(str));
    str[len] = '\0';
    printf("%s",str);

    close(fd);
    return 0;
}